import namespace from "../namespace";

namespace.io.Reader = {
  render(canvas, json) {
    if (typeof json === "string") {
      json = JSON.parse(json);
    }

    json.forEach(attr => {
      let f = this.createFigureFromType(attr.type);
      f.setPersistentAttrs(attr);
      canvas.addFigure(f);
    });
  },

  createFigureFromType: function (type) {
    return eval("new " + type + "()");
  }
};
